import Vue from 'vue'
import Vuex from 'vuex'
import axios from "axios"
Vue.use(Vuex)

export default new Vuex.Store({
  state:{
    dataList:[],
    status:'all',
    detail:{},
    showCon:false,
    
  },
  mutations:{
    SET_DATA_LIST(state,data){
      state.dataList=data;
    },
    SET_STATUS(state,status){
      state.status=status;
    },
    SET_DETAIL(state,data){
      state.detail=data;
    },
    SET_SHOW_CON(state,boo){
      state.showCon=boo;
    }
  },
  actions:{
    
    async setDataList({commit},tab){
      let res=await axios.get('https://cnodejs.org/api/v1/topics?tab='+tab);
      console.log(res);
      commit('SET_DATA_LIST',res.data.data)
    },

    
    setStatus({commit},status){
      commit('SET_STATUS',status)
    },
    setDetail({commit},id){
      axios.get('https://cnodejs.org/api/v1/topic/'+id).then(res=>{
        console.log(res.data.data);
        commit('SET_DETAIL',res.data.data)
      })
      
    },
    showContent({commit},boo){
      commit('SET_SHOW_CON',boo)
    }
  }
})